package nl.weeaboo.sh.level1;

import nl.weeaboo.game.input.UserInput;
import nl.weeaboo.sh.Game;
import nl.weeaboo.sh.level.Level;
import nl.weeaboo.sh.objects.Enemy;
import nl.weeaboo.sh.objects.Player;
import nl.weeaboo.sh.view.anim.Animation;

public class FlyingSkull extends Enemy {
	
	public FlyingSkull(Game game, Level level) {
		super(game, level, game.getCharaImage("object/skull.png#walk1"));
		
		floating = true;
		dontWalkOffLedges = false;
		knockbackInertia = 1000000f;
		
		dir = -1;
		maxHp = hp = 5; 
		setSpeed(-5, -1 + random.nextInt(3));
		setPower(4);
		
		a_walk = Animation.create(game, "object/skull.png", true,
				"walk1", 6, "walk2", 6, "walk3", 6, "walk2", 6);
		a_attack = Animation.create(game, "object/skull.png", false,
				"attack1", 6, "attack2", 6, "attack1", 6);
		
		anim = a_walk;
	}

	//Functions	
	protected int recalculateAttackFrame() {
		return 30;		
	}
	protected void attack() {
		//setSpeed(dir * 10.0f, -10.0f);		
	}
	
	public void update(UserInput input, float dt) {
		Player player = level.getPlayer();		
		if (dir == -1) {
			if (x < player.getX() - 400) {
				dir = 1; speedX = Math.abs(speedX);
			}
		} else {
			if (x > player.getX() + 400) {
				dir = -1; speedX = -Math.abs(speedX);
			}
		}
		if (y < player.getY() - 400) {
			speedY = Math.abs(speedY);
		} else if (y > player.getY() + 200) {
			speedY = -Math.abs(speedY);
		}
		
		if (Math.abs(x - player.getX()) < 800 || Math.abs(y - player.getY()) < 600) {
			super.update(input, dt);
		}
	}
	
	protected void collide(int dx, int dy) {
		//No level collisions
		x += dx;
		y += dy;
	}
	
	//Getters
	
	//Setters
	
}
